package mapper

import (
	"gin-epg/internal/app/dao"
	"gin-epg/internal/app/entity"
)

/*
*
根据平台id获取epgChannel集合
*/
func GetToolMulticastChannelByPlatformId(ptId string) (toolMulticastChannelList []*entity.ToolMulticastChannel, err error) {
	query := dao.SqlSession.Model(&entity.ToolMulticastChannel{})

	if err := query.Where("multicast_platform_id = ?", ptId).Find(&toolMulticastChannelList).Error; err != nil {
		return nil, err
	}
	return
}

// CreateToolMulticastChannel 创建一个新的 ToolMulticastChannel
func CreateToolMulticastChannel(toolMulticastChannel *entity.ToolMulticastChannel) (err error) {
	if err = dao.SqlSession.Create(toolMulticastChannel).Error; err != nil {
		return err
	}
	return
}

/*
* 获取 ToolMulticastChannel 集合
 */
func GetAllToolMulticastChannel() (toolMulticastChannelList []*entity.ToolMulticastChannel, err error) {
	if err := dao.SqlSession.Find(&toolMulticastChannelList).Error; err != nil {
		return nil, err
	}
	return
}

/*
* 根据 id 删除 ToolMulticastChannel
 */
func DeleteToolMulticastChannelById(id string) (err error) {
	err = dao.SqlSession.Where("id=?", id).Delete(&entity.ToolMulticastChannel{}).Error
	return
}

/*
* 根据 id 查询 ToolMulticastChannel
 */
func GetToolMulticastChannelById(id string) (toolMulticastChannel *entity.ToolMulticastChannel, err error) {
	// 初始化 toolMulticastChannel 变量
	toolMulticastChannel = new(entity.ToolMulticastChannel)

	// 执行查询
	if err = dao.SqlSession.Where("id=?", id).First(toolMulticastChannel).Error; err != nil {
		return nil, err
	}
	return toolMulticastChannel, nil
}

/*
* 更新 ToolMulticastChannel 信息
 */
func UpdateToolMulticastChannel(toolMulticastChannel *entity.ToolMulticastChannel) (err error) {
	err = dao.SqlSession.Save(toolMulticastChannel).Error
	return
}
